package com.hou.controller;

import com.hou.pojo.UserLogin;
import com.hou.services.UserLoginServicesImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

public class LoginController {
   @Autowired
   UserLoginServicesImpl userLoginServices;
   @RequestMapping("/toLogin")
   public String toLogin(){
       return "login";
   }
   @RequestMapping("/LogingSuccess")
   public String LogingSuccess(Model model, UserLogin userLogin){
       UserLogin userLogin1 = userLoginServices.queryByName(userLogin.getUsername());
       if(userLogin1 != null){ //  如果查询的用户不为空
           System.out.println(userLogin1.toString());
           return "success";
       }
       else{
           //返回到登录页面
           model.addAttribute("data","该用户不存在，请先注册");
           return "login";
       }
   }

    //登录界面
    @RequestMapping("/toRegister")
    public String toRegister(){
        return "register";
    }
    @RequestMapping("/RegisterSuccess")
    public String toRegisterSuccess(Model model,UserLogin userLogin){
        //将账号密码加入到数据库中
        int add = userLoginServices.add(userLogin);
        System.out.println("数据插入成功！");
        model.addAttribute("data","注册成功，请登录！");
        return "login";
    }
}
